package com.demo.springBootDemo08.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.demo.springBootDemo08.dao.DeptMapper;
import com.demo.springBootDemo08.entity.Dept;
import com.demo.springBootDemo08.service.DeptService;

@Service
public class DeptServiceImpl implements DeptService {

	@Autowired
	private DeptMapper deptMapper;

	@Override
	public List<Dept> findList() {
		return deptMapper.findAll();
	}

	@Override
	public Dept getByPrimaryKey(Integer deptno) {
		return deptMapper.findOne(deptno);
	}

	@Override
	public Dept addDept(Dept dept) {
		deptMapper.save(dept);
		return dept;
	}

	@Override
	public Dept updateDept(Integer deptno, Dept dept) {
		Dept deptOrg = deptMapper.findOne(deptno);
		Assert.isTrue(deptOrg != null, "");
		deptMapper.save(dept);
		return deptOrg;
	}

	@Override
	public Dept deleteByPrimaryKey(Integer deptno) {
		Dept deptOrg = deptMapper.findOne(deptno);
		Assert.isTrue(deptOrg != null, "");
		deptMapper.delete(deptno);
		return deptOrg;
	}

}
